/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aybolit.core.objects.dao.impl;


import aybolit.core.objects.dao.OperatorsDao;
import aybolit.core.objects.model.Operators;
import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Masumov Emin
 */
@Transactional
public class OperatorsDaoImpl implements OperatorsDao,Serializable{
 SessionFactory sessionFactory;
    @Override
    public void addOperators(Operators operators) {

        operators.setLogin("Emin");
        sessionFactory.getCurrentSession().save(operators);
    }
    @Transactional(readOnly=true)
    @Override
    public List<Operators> findAlloperators() {
       return sessionFactory.getCurrentSession().getNamedQuery("Operators.findAlloperators1").list();
    }

    @Override
    public Operators findAlloperators(String login) {
   Operators o=(Operators) sessionFactory.getCurrentSession().getNamedQuery("Operators.findAlloperators").setParameter("login", login).uniqueResult();     
      return  o;
//        DetachedCriteria criteria = DetachedCriteria.forClass(Operators.class).add(Restrictions.eq("login", login));
//        return getHibernateTemplate().findByCriteria(criteria);
    }
    @Resource(name="sessionFactory")
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

}
